<template>
  <page-header-wrapper>
    <a-card :bordered="false">

      <div class="table-page-search-wrapper">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="6" :sm="24">
              <a-form-item label="状态">
                <a-select v-model="paystatus" placeholder="请选择医生状态">
                  <a-select-option :value="0">全部</a-select-option>
                  <a-select-option :value="1">待付款</a-select-option>
                  <a-select-option :value="2">已付款</a-select-option>
                  <a-select-option :value="3">待收货</a-select-option>
                  <a-select-option :value="4">已完成</a-select-option>
                  <a-select-option :value="-1">已撤回</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="12" :sm="24">
              <a-button type="primary" @click="handleSearch">查询</a-button>
              <a-button style="margin-left: 8px" @click="resetSearch">重置</a-button>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <a-table :scroll="{ x: true }" ref="table" @change="tablePaginationChange" :pagination="pagination" bordered
        :dataSource="dataSource" :columns="columns" :rowKey="(record,index)=> index">
        <img @click="previewImg(record.qianming)" class="banner-img" slot-scope="text, record" :src="text"
          slot="qianming" />
        <div slot="price" slot-scope="text, record">
          ¥{{text}}
        </div>
        <div slot="zhenjin" slot-scope="text, record">
          ¥{{text}}
        </div>

        <div slot="ziti" slot-scope="text, record">
          {{text==1?'快递':'自提'}}
        </div>
        <div slot="paystatus" slot-scope="text, record">
          <span :style="{'color': getColor(text) }">
            {{getpaystatus(text)}}
          </span>
        </div>
        <div slot="addtime" slot-scope="text, record">
          {{ new Date(text * 1000).toLocaleString() }}
        </div>
        <div slot="action" slot-scope="text, record" href="javascript:;">
          <a-button size='small' type="link" @click='showDetail(record)'>
            详情
          </a-button>
        </div>
      </a-table>
    </a-card>
    <!-- <addBox ref="addBox" :visible="addFlag" @cancel="addCancel" @ok="AddSuccess">
    </addBox> -->
    <imgBox ref='preimg'></imgBox>
  </page-header-wrapper>

</template>

<script>
  import {
    STable,
    Ellipsis,
  } from '@/components'
  import {
    zhongyaoOrder
  } from '@/api/orderManage'
  // import addBox from './add'
  import imgBox from '@/components/previewImg/index'

  import {
    ExclamationCircleOutlined
  } from '@ant-design/icons-vue';
  import {
    createVNode
  } from 'vue';
  import {
    Modal,
    message
  } from 'ant-design-vue';

  export default {
    components: {
      STable,
      Ellipsis,
      // addBox,
      imgBox
    },
    data() {
      return {
        searchflag: false,
        shenhe: 0, //审核
        paystatus: 0, //状态
        addFlag: false,
        pagination: {
          current: 1, //默认当前叶数
          total: 0, // 数据总数 如果不设置就以绑定的数据量为准
          pageSize: 10, // 默认每页条数
          showSizeChanger: true, //是否可以改变 pageSize
          pageSizeOptions: ['10', '20', '40', '80', '100'], //可切换每叶数据条数
          showTotal: total => this.$t('共') + ' ' + `${total}` + ' ' + this.$t('条数据'), // 分页中显示总的数据
          hideOnSinglePage: false // 只有一页时是否隐藏分页器 true为不显示 false为显示
        },
        dataSource: [],
        columns: [{
            title: 'id',
            dataIndex: 'id',
            key: 'id',
            width: 70,
          },
          // {
          //   title: '医生签名',
          //   key: 'qianming',
          //   dataIndex: 'qianming',
          //   width: 100,
          //   scopedSlots: {
          //     customRender: 'qianming'
          //   }
          // },
          {
            title: '姓名',
            key: 'name',
            dataIndex: 'name',
          },
          {
            title: '配送方式',
            key: 'ziti',
            dataIndex: 'ziti',
            scopedSlots: {
              customRender: 'ziti'
            }
          },
          // {
          //   title: '辨病',
          //   key: 'bianbing',
          //   dataIndex: 'bianbing',
          // },
          // {
          //   title: '辨证',
          //   key: 'bianzheng',
          //   dataIndex: 'bianzheng',
          // },
          {
            title: '店铺',
            key: 'pharmacyname',
            dataIndex: 'pharmacyname',
          },

          {
            title: '诊金',
            key: 'zhenjin',
            dataIndex: 'zhenjin',
            scopedSlots: {
              customRender: 'zhenjin'
            }
          },
          {
            title: '总价',
            key: 'price',
            dataIndex: 'price',
            scopedSlots: {
              customRender: 'price'
            }
          },
          {
            title: '添加时间',
            key: 'addtime',
            dataIndex: 'addtime',
            scopedSlots: {
              customRender: 'addtime'
            }
          },
          {
            title: '状态',
            key: 'paystatus',
            dataIndex: 'paystatus',
            scopedSlots: {
              customRender: 'paystatus'
            }
          },

          {
            title: '操作',
            key: 'operation',
            fixed: 'right',
            width: 100,
            scopedSlots: {
              customRender: 'action'
            }
          }
        ],
      }
    },
    created() {
      this.getList()
    },
    methods: {
      getColor(v) {
        switch (v) {
          case 0:
            return ''
            break;
          case 1:
            return ''
            break;
          case 2:
            return '#0f90ff '
            break;
          case 3:
            return '#f35b0e '
            break;
          default:
            return ''
            break
        }
      },
      showDetail(v) {
        this.$router.push({
          path: '/zhongyaoOrderListDetail',
          query: {
            id: v.id
          }
        })
      },
      getpaystatus(v) {
        switch (v) {
          case 0:
            return '全部'
            break;
          case -1:
            return '已撤回'
            break;
          case 1:
            return '待付款'
            break;
          case 2:
            return '已付款'
            break;
          case 3:
            return '待收货'
            break;
          default:
            return '已完成'
            break
        }
      },
      authInfo(val) {
        doctorAuth({
          id: val.id
        }).then(res => {
          message.info('审核成功');
          this.getList(0)
        })
      },
      previewImg(img) {
        this.$refs.preimg.initData(img)
      },
      getList() {
        zhongyaoOrder({
          pageNo: this.pagination.current,
          pageSize: this.pagination.pageSize,
          paystatus: this.searchflag ? this.paystatus : 0
        }).then(res => {
          this.pagination.total = res.data.totalCount
          this.dataSource = res.data.data
        })
      },
      handleSearch() {
        this.searchflag = true
        this.pagination.current = 1
        this.getList()
      },
      resetSearch() {
        this.searchflag = false
        this.paystatus = 0
        this.pagination.current = 1
        this.getList()
      },
      updateInfo(val) {
        this.addFlag = true
        this.$nextTick(() => {
          this.$refs.addBox.setUpdate(val)
        })
      },

      addCancel() {
        this.addFlag = false
      },
      AddSuccess() {
        this.addFlag = false
        this.getList()
      },
      addStore() {
        this.addFlag = true
        this.$nextTick(() => {
          this.$refs.addBox.updateflag = false
        })
      },
      tablePaginationChange(e) {
        this.pagination = e
        this.getList()
      },
      getDate(stamp) {
        var date = new Date(stamp * 1000)
        return date.getFullYear() + '-' + (date.getMonth() + 1 < 10 ? ('0' + (date.getMonth() + 1)) : date.getMonth() +
          1) + '-' + (date.getDate() < 10 ? '0' + date.getDate() : date.getDate())
      },
      deletInfo(val) {
        hospitalDelet(val.id).then(res => {
          this.getList()
        })
      }
    }
  }
</script>
<style scoped>
  .banner-img {
    width: 50px;
    height: 50px;
    border-radius: 5px;
    cursor: pointer;
  }
</style>